<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //创建一个类
    class Person {
      //属性写到构造方法函数里
      constructor(name, age) {
        this.name = name;
        this.age = age;
      }
      //方法
      eat() {
        console.log(this.name + ' is eating');
      }

    }
    //通过类创建对象
    var p1 = new Person('lisi', 50);
    console.log(p1);
    p1.eat();

    class Student extends Person {
      constructor(name, age, school) {
        super(name, age);
        this.school = school;
      }
      code() {
        console.log(this.name + ' is coding');
      }
    }
    var s1 = new Student('ninging', 20, '金融');
    console.log(s1);
    s1.code();
    s1.eat();
  </script>
</body>

</html>